package com.bill.common.news.service;

import com.bill.common.news.dao.ITopicDAO;
import com.bill.common.news.dto.TopicDTO;
import com.bill.common.news.entity.Topic;
import com.sinba.common.dto.PageDTO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

public class TopicService
    implements ITopicService
{
    @Autowired
    private ITopicDAO topicDAO;

    //��ҳ
    /* (non-Javadoc)
     * @see com.sinba.common.news.service.ITopicService#findTopicPager(com.sinba.common.news.dto.TopicDTO, java.lang.String, java.lang.String)
     */
    @Transactional
    public PageDTO findTopicPager( TopicDTO dto, String sord, String sidx )
    {
        PageDTO p = topicDAO.findTopicPager( dto, sord, sidx );
        List<Topic> topicList = (List<Topic>) p.getData(  );
        List<TopicDTO> topicDTOList = new ArrayList<TopicDTO>(  );

        for ( Topic entity : topicList )
        {
            TopicDTO topicDTO = new TopicDTO(  );
            topicDTO.entity2dto( entity, topicDTO );
            topicDTOList.add( topicDTO );
        }

        p.setData( topicDTOList );

        return p;
    }

    //����
    /* (non-Javadoc)
     * @see com.sinba.common.news.service.ITopicService#saveTopic(com.sinba.common.news.dto.TopicDTO)
     */
    @Transactional
    public void saveTopic( TopicDTO dto )
    {
        Topic enttiy = new Topic(  );
        dto.dto2entity( dto, enttiy );
        topicDAO.save( enttiy );
    }
    ;

    //�༭
    /* (non-Javadoc)
     * @see com.sinba.common.news.service.ITopicService#editTopic(com.sinba.common.news.dto.TopicDTO)
     */
    @Transactional
    public void editTopic( TopicDTO dto )
    {
        Topic enttiy = new Topic(  );
        dto.dto2entity( dto, enttiy );

        topicDAO.merge( enttiy );
    }
    ;

    //ɾ��
    /* (non-Javadoc)
     * @see com.sinba.common.news.service.ITopicService#deleteTopic(java.lang.Long[])
     */
    @Transactional
    public void deleteTopic( Long[] ids )
    {
        topicDAO.deleteByIds( ids );
    }
    ;

    //��ϸ
    @Transactional
    public TopicDTO findTopicInfo( Long id )
    {
        Topic topic = topicDAO.findById( id );
        TopicDTO dto = new TopicDTO(  );
        dto.entity2dto( topic, dto );

        return dto;
    }
    ;
}
